import { useState } from "react";
import { Alert, AppRegistry, Button, NativeEventEmitter, NativeModules, Text, View } from "react-native";
// const { KeyboardViewModule } = NativeModules;
// const keyboardEmitter = new NativeEventEmitter(KeyboardViewModule);

export default function KeyboardView() {

  const [title, setTitle] = useState('React Native ToolBar');
  const insertAction = () => {

    console.log(`insertAction ${NativeModules.KeyboardViewModule ?? 'nil'}`);
        console.log('所有可用原生模块:', Object.keys(NativeModules));
    setTitle(`确认插入文本吗 `);
    NativeModules.KeyboardViewModule.insertText('hello world');

  }
  return (
    <View style={{backgroundColor: 'red'}}>
       <Text style={{width:'100%', textAlign:'center'}}>{title}</Text>
       <Button title="Insert Text" onPress={insertAction}/>
    </View>
  );
}

